﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;
using System.Globalization;
using Public;

namespace WebsiteAdmin.Wilson.ProInfo.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class CatInsert : IHttpHandler
    {
        string catName = string.Empty;
        string catCode = string.Empty;
        string imgURL = string.Empty;
        string description = string.Empty;
        int sortBy = 0;
        
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Cookie.AdminLoginName != null || Cookie.AdminLoginName != "")
            {
                int rtn = 0;
                InitData(context);
                rtn = Insert(Global.ConnWilson, catName, catCode, imgURL, description, sortBy);
                context.Response.Write(rtn == 1 ? "{\"Done\":\"Success\"}" : "{\"Done\":\"Failed\"}");
            }
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        protected void InitData(HttpContext context) 
        {
            catName = context.Request["CatTitle"].ToString();
            catCode = context.Request["UrlName"].ToString();
            imgURL = context.Request["ImgURL"].ToString();
            description = context.Request["Description"].ToString();
            sortBy = Convert.ToInt32(context.Request["SortBy"],CultureInfo.InvariantCulture);
        }

        protected int Insert(string strCon,string catName,string catCode,string imgURL,string description,int sortBy) 
        {
            return Bll.Category.Insert(strCon, catName, catCode, imgURL, description,sortBy);
        }
    }
}
